package org.davidliebman.android.awesomecube;

import java.util.ArrayList;

import javax.microedition.khronos.opengles.GL;

import android.os.*;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.EGLConfigChooser;
import android.util.*;
import android.content.*;


public class CubeGLSurfaceView extends  GLSurfaceView{

	public OpenGLRenderer renderer;
	Context mContext;
	
	OrientationArray mArray = new OrientationArray();
		
	boolean mTestAnimation = true;
	
	public CubeGLSurfaceView(Context c, AttributeSet a) {
		super (c , a);
		mContext = c;
		setFocusable(true);
		//this.setEGLConfigChooser(true);
		
	
		renderer = new OpenGLRenderer(c);
		this.setRenderer(renderer);
		MeshList mPieces = new MeshList(mContext);

		buildCube();
	}
	
	public void buildCube() {
		//MeshList mPieces = new MeshList(mContext);
		
	
		/////////////////////CORNERS:
		SimpleCorner mCorner1 = new SimpleCorner(mContext, new Positioning(Mesh.XPOS , Mesh.YPOS , Mesh.ZNEG) , 
				TextureLibrary.BLUE, TextureLibrary.RED, TextureLibrary.WHITE);//blue, orange, white
		mCorner1.setName("blue,red,white,1");
		mArray.add(mCorner1, 2, 2, 0);
		
		SimpleCorner mCorner2 = new SimpleCorner(mContext, new Positioning(Mesh.XPOS, Mesh.YNEG, Mesh.ZNEG) , 
				TextureLibrary.BLUE, TextureLibrary.ORANGE, TextureLibrary.WHITE);// blue, white, red
		mCorner2.setName("blue,orange,white,2");
		mArray.add(mCorner2, 2, 0, 0);
		
		SimpleCorner mCorner3 = new SimpleCorner(mContext, new Positioning(Mesh.XNEG, Mesh.YNEG, Mesh.ZNEG),  
				TextureLibrary.GREEN, TextureLibrary.ORANGE, TextureLibrary.WHITE); // yellow, orange, blue
		mCorner3.setName("green,orange,white,3");
		mArray.add(mCorner3, 0, 0, 0);
		
		SimpleCorner mCorner4 = new SimpleCorner(mContext, new Positioning(Mesh.XNEG, Mesh.YPOS, Mesh.ZNEG),  
				TextureLibrary.GREEN, TextureLibrary.RED, TextureLibrary.WHITE); // blue, red, yellow
		mCorner4.setName("green,red,white,4");
		mArray.add(mCorner4, 0, 2, 0);
		 
		SimpleCorner mCorner5 = new SimpleCorner(mContext, new Positioning(Mesh.XPOS, Mesh.YPOS, Mesh.ZPOS),  //2,2,0
				TextureLibrary.BLUE, TextureLibrary.RED, TextureLibrary.YELLOW); // green, red, white
		mCorner5.setName("blue,red,yellow,5");
		mArray.add(mCorner5, 2, 2, 2);// 0,2,0
		
		SimpleCorner mCorner6 = new SimpleCorner(mContext, new Positioning(Mesh.XPOS, Mesh.YNEG, Mesh.ZPOS),  
				TextureLibrary.BLUE, TextureLibrary.ORANGE, TextureLibrary.YELLOW); // yellow, red, green
		mCorner6.setName("blue,orange,yellow,6");
		mArray.add(mCorner6, 2, 0, 2);
		
		SimpleCorner mCorner7 = new SimpleCorner(mContext, new Positioning(Mesh.XNEG, Mesh.YNEG, Mesh.ZPOS),
				TextureLibrary.GREEN, TextureLibrary.ORANGE, TextureLibrary.YELLOW);// orange, yellow, green
		mCorner7.setName("green,orange,yellow,7");
		mArray.add(mCorner7, 0, 0, 2);
		
		SimpleCorner mCorner8 = new SimpleCorner(mContext, new Positioning(Mesh.XNEG , Mesh.YPOS , Mesh.ZPOS),//3,3,3~0,0,1
				TextureLibrary.GREEN, TextureLibrary.RED, TextureLibrary.YELLOW); // white, orange, green
		mCorner8.setName("green,red,yellow,8");
		mArray.add(mCorner8, 0, 2, 2);
		
		///////////EDGES:
		SimpleEdge	mEdge1 = new SimpleEdge(mContext, new Positioning ( Mesh.XPOS, Mesh.YNEG, Mesh.MIDD),  
				TextureLibrary.BLUE, TextureLibrary.ORANGE, TextureLibrary.NONE); // blue, orange
		mArray.add(mEdge1, 2, 0, 1);
		
		SimpleEdge	mEdge2 = new SimpleEdge(mContext, new Positioning ( Mesh.MIDD, Mesh.YNEG, Mesh.ZNEG),  
				TextureLibrary.NONE, TextureLibrary.ORANGE, TextureLibrary.WHITE); // 
		mArray.add(mEdge2, 1, 0, 0);
		
		SimpleEdge	mEdge3 = new SimpleEdge(mContext, new Positioning ( Mesh.XNEG, Mesh.YNEG, Mesh.MIDD),  
				TextureLibrary.GREEN, TextureLibrary.ORANGE, TextureLibrary.NONE); //  
		mArray.add(mEdge3, 0, 0, 1);
		
		SimpleEdge	mEdge4 = new SimpleEdge(mContext, new Positioning ( Mesh.XNEG, Mesh.MIDD, Mesh.ZNEG),  
				TextureLibrary.GREEN,TextureLibrary.NONE, TextureLibrary.WHITE); // 
		mArray.add(mEdge4, 0, 1, 0);
		
		SimpleEdge	mEdge5 = new SimpleEdge(mContext, new Positioning ( Mesh.MIDD, Mesh.YPOS, Mesh.ZNEG),  
				TextureLibrary.NONE, TextureLibrary.RED, TextureLibrary.WHITE); // 
		mArray.add(mEdge5, 1, 2, 0);
		
		SimpleEdge	mEdge6 = new SimpleEdge(mContext, new Positioning ( Mesh.XPOS, Mesh.MIDD, Mesh.ZNEG),  
				TextureLibrary.BLUE,TextureLibrary.NONE, TextureLibrary.WHITE); // 
		mArray.add(mEdge6, 2, 1, 0);
		
		SimpleEdge	mEdge7 = new SimpleEdge(mContext, new Positioning ( Mesh.XPOS, Mesh.YPOS, Mesh.MIDD),  
				TextureLibrary.BLUE, TextureLibrary.RED, TextureLibrary.NONE); // 
		mArray.add(mEdge7, 2, 2, 1);
		
		SimpleEdge	mEdge8 = new SimpleEdge(mContext, new Positioning ( Mesh.XPOS, Mesh.MIDD, Mesh.ZPOS),  
				TextureLibrary.BLUE, TextureLibrary.NONE, TextureLibrary.YELLOW); // 
		mArray.add(mEdge8, 2, 1, 2);
		
		SimpleEdge	mEdge9 = new SimpleEdge(mContext, new Positioning ( Mesh.MIDD, Mesh.YPOS, Mesh.ZPOS),  
				TextureLibrary.NONE, TextureLibrary.RED, TextureLibrary.YELLOW); // 
		mArray.add(mEdge9, 1, 2, 2);
		
		SimpleEdge	mEdge10 = new SimpleEdge(mContext, new Positioning ( Mesh.XNEG, Mesh.YPOS, Mesh.MIDD),  
				TextureLibrary.GREEN, TextureLibrary.RED, TextureLibrary.NONE); // 
		mArray.add(mEdge10, 0, 2, 1);
		
		SimpleEdge	mEdge11 = new SimpleEdge(mContext, new Positioning ( Mesh.XNEG, Mesh.MIDD, Mesh.ZPOS),  
				TextureLibrary.GREEN, TextureLibrary.NONE, TextureLibrary.YELLOW); // 
		mArray.add(mEdge11, 0, 1, 2);
		
		SimpleEdge	mEdge12 = new SimpleEdge(mContext, new Positioning ( Mesh.MIDD, Mesh.YNEG, Mesh.ZPOS),  
				TextureLibrary.NONE, TextureLibrary.ORANGE, TextureLibrary.YELLOW); // 
		mArray.add(mEdge12, 1, 0, 2);
		
		////////////CENTERS:
		SimpleCenter mCenter1 = new SimpleCenter(mContext, new Positioning ( Mesh.XPOS, Mesh.MIDD, Mesh.MIDD), 
				TextureLibrary.BLUE, TextureLibrary.NONE, TextureLibrary.NONE); // blue
		mArray.add(mCenter1, 2, 1, 1);
		
		SimpleCenter mCenter2 = new SimpleCenter(mContext, new Positioning ( Mesh.MIDD, Mesh.MIDD, Mesh.ZNEG), 
				TextureLibrary.NONE, TextureLibrary.NONE ,TextureLibrary.WHITE); // white
		mArray.add(mCenter2, 1, 1, 0);
		
		SimpleCenter mCenter3 = new SimpleCenter(mContext, new Positioning ( Mesh.XNEG, Mesh.MIDD, Mesh.MIDD), 
				TextureLibrary.GREEN, TextureLibrary.NONE, TextureLibrary.NONE); // green
		mArray.add(mCenter3, 0, 1, 1);
		
		SimpleCenter mCenter4 = new SimpleCenter(mContext, new Positioning ( Mesh.MIDD, Mesh.YNEG, Mesh.MIDD), 
				TextureLibrary.NONE, TextureLibrary.ORANGE, TextureLibrary.NONE); // yellow
		mArray.add(mCenter4, 1, 0, 1);
		
		SimpleCenter mCenter5 = new SimpleCenter(mContext, new Positioning ( Mesh.MIDD, Mesh.MIDD, Mesh.ZPOS), 
				TextureLibrary.NONE, TextureLibrary.NONE, TextureLibrary.YELLOW); // red
		mArray.add(mCenter5, 1, 1, 2);
		
		SimpleCenter mCenter6 = new SimpleCenter(mContext, new Positioning ( Mesh.MIDD, Mesh.YPOS, Mesh.MIDD), 
				TextureLibrary.NONE, TextureLibrary.RED, TextureLibrary.NONE); // orange
		mArray.add(mCenter6, 1, 2, 1);
	
		mArray.setTiles();
		
		renderer.addArray(mArray);
		
//		if (mTestAnimation) {
//			renderer.startAnimation(mArray.mOrientation, mArray.mTile,new UsedXYZ(UsedXYZ.ALL, UsedXYZ.ALL, UsedXYZ.ALL), 
//				MeshList.ANIMATION_DECREASING, MeshList.AXIS_Y, MeshList.LIMIT_360);
//			mTestAnimation = false; 
//		} else {
//			//renderer.startAnimation(new UsedXYZ(UsedXYZ.ALL, UsedXYZ.ALL, UsedXYZ.ALL), 
//			//		MeshList.ANIMATION_NONE, 0, 0);
//		}
	}
	
	
}
